package com.aaa.jx.controller;

import com.aaa.jx.entity.TSdsRecord;
import com.aaa.jx.entity.TSdsReturn;
import com.aaa.jx.service.TSdsRecordService;
import com.aaa.jx.service.impl.TSdsRecordServiceImpl;
import com.util.LayData;
import com.util.LayPage;
import com.util.PrintJsonData;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

@WebServlet(name = "TSdsReturnServlet", value = "/TSdsReturnServlet")
public class TSdsReturnServlet extends HttpServlet{
    private TSdsRecordService tSdsRecordService = new TSdsRecordServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        TSdsReturn tSdsReturn=new TSdsReturn();

        String method = req.getParameter("method");
        if (method==null){
            String page = req.getParameter("page");
            String limit = req.getParameter("limit");
            LayPage layPage=new LayPage(page,limit);
            layPage.setStart(layPage.getStart());
            List<TSdsReturn> tSdsReturns = tSdsRecordService.queryReturn(layPage);
            LayData success=new LayData(0,"",0L,tSdsReturns);
            PrintJsonData.printData(resp,success);
        }else if(method.equals("insert")){
            String tel = req.getParameter("tel");
            String text = req.getParameter("text");
            TSdsRecord tSdsRecord = tSdsRecordService.queryByTel(tel);
            tSdsReturn.setRecordid(tSdsRecord.getId());
            tSdsReturn.setUsername(tSdsRecord.getUsername());
            tSdsReturn.setTel(tel);
            tSdsReturn.setCreatetime(text);
            tSdsRecordService.insertReturn(tSdsReturn);
            LayData success=new LayData( 0L,null);
            PrintJsonData.printData(resp,success);
        }
    }
}

